package com.wlhse.controller;

import com.wlhse.dto.CheckPerson;
import com.wlhse.dto.CheckPersonDto;
import com.wlhse.dto.HseCheckRecordDto;
import com.wlhse.dto.RectCheckRecordDto;
import com.wlhse.dto.inDto.CheckRecordIDDto;
import com.wlhse.entity.CheckPersonPojo;
import com.wlhse.entity.QHSEECheckRecordPojo;
import com.wlhse.service.HSECheckRecordService;
import com.wlhse.service.SupervisionTaskService2;
import com.wlhse.util.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController("HSECheckRecordController")
@RequestMapping("/api/v1/hsecheckRecord")
public class HSECheckRecordController {
    @Resource
    private HSECheckRecordService hseCheckRecordService;

    @Resource
    private SupervisionTaskService2 supervisionTaskService2;

    //公司code和起止时间查询审核记录(只显示当前登录人相关的)
    // 4.6组长调用
    @RequestMapping(value = "/queryQHSEECheckRecordByHeadman",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public String queryQHSEECheckRecordByHeadman(@ModelAttribute HseCheckRecordDto hseCheckRecordDto,HttpServletRequest request){
        return hseCheckRecordService.queryQHSEECheckRecordByHeadman(hseCheckRecordDto,request);
    }

    //公司code和起止时间查询审核记录(只显示当前登录人相关的)
    // 4.6管理员调用
    @RequestMapping(value = "/queryQHSEECheckRecordByAdmin",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public String queryQHSEECheckRecordByAdmin(@ModelAttribute HseCheckRecordDto hseCheckRecordDto,HttpServletRequest request){
        return hseCheckRecordService.queryQHSEECheckRecordByAdmin(hseCheckRecordDto,request);
    }


    //审核问题，可修改问题（未审核|组长已审核|管理员已审核|已整改）
    // 4.6 组长调用
    @RequestMapping(value = "/updateRecordStatusByHeadman",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public String updateRecordStatusByHeadman(@ModelAttribute QHSEECheckRecordPojo qhseeCheckRecordPojo,HttpServletRequest request){
        return hseCheckRecordService.updateRecordStatusByHeadman(qhseeCheckRecordPojo,request);
    }

    //审核问题，可修改问题（未审核|组长已审核|管理员已审核|已整改）
    // 4.6 管理员调用
    @RequestMapping(value = "/updateRecordStatusByAdmin",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public String updateRecordStatusByAdmin(@ModelAttribute QHSEECheckRecordPojo qhseeCheckRecordPojo,HttpServletRequest request){
        return hseCheckRecordService.updateRecordStatusByAdmin(qhseeCheckRecordPojo,request);
    }

    //删除审核记录
    @RequestMapping(value = "/deleteCheckRecord",method = RequestMethod.DELETE,produces = "application/json; charset=utf-8")
    public String deleteCheckRecord(@RequestParam(value = "qHSEECheckRecordID",required = false) Integer qHSEECheckRecordID){
        return hseCheckRecordService.deleteCheckRecord(qHSEECheckRecordID);
    }

    //查询待整改的问题
    @RequestMapping(value = "/queryCheckRecordByID",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public String queryCheckRecordByID(@ModelAttribute HseCheckRecordDto hseCheckRecordDto,HttpServletRequest request){
        return hseCheckRecordService.queryCheckRecordByID(hseCheckRecordDto,request);
    }

    //提交整改未整改的问题
    @RequestMapping(value = "/updateRectCheckRecord",method = RequestMethod.POST,produces = "application/json; charset=utf-8")
    public String updateRectCheckRecord(@RequestBody RectCheckRecordDto rectCheckRecordDto,HttpServletRequest request){
        return hseCheckRecordService.updateRectCheckRecord(rectCheckRecordDto,request);
    }

    //保存HSE审核人员
    @ApiOperation("保存HSE审核人员")
    @RequestMapping(value = "/addCheckperson",method = RequestMethod.POST,produces = "application/json; charset=utf-8")
    public String addCheckperson(@RequestBody CheckPersonDto CheckPersonDto){
        return hseCheckRecordService.addCheckperson(CheckPersonDto);
    }
    @ApiOperation("修改HSE审核人员")
    @RequestMapping(value = "/updateCheckperson",method = RequestMethod.POST,produces = "application/json; charset=utf-8")
    public String updateCheckperson(@RequestBody CheckPersonDto CheckPersonDto){
        return hseCheckRecordService.updateCheckperson(CheckPersonDto);
    }
    //查询公司的员工信息
    @RequestMapping(value = "/queryCheckperson",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public String queryCheckperson(){
        return supervisionTaskService2.queryHSECheckPerson();
    }

    //查询公司的员工信息(根据code)
    @RequestMapping(value = "/queryCheckpersonByCode",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public String queryCheckpersonByCode(@RequestParam(value = "companyCode",required = false) String companyCode){
        return supervisionTaskService2.queryCheckpersonByCode(companyCode);
    }

    //查询当前所有的HSE审核人
    @RequestMapping(value = "/queryAllCheckPerson",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public String queryAllCheckPerson(@RequestParam(value = "num",required = false) Integer num,
                                      @RequestParam(value = "size",required = false) Integer size){
        return hseCheckRecordService.queryAllCheckPerson(num,size);
    }

    //查询组长，用RoleName查
    @RequestMapping(value = "/queryHeadman",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public String queryHeadman(@RequestParam(value = "num",required = false) Integer num,
                               @RequestParam(value = "size",required = false) Integer size){
        return hseCheckRecordService.queryHeadman(num,size);
    }

    //查询组员，用RoleName查
    @RequestMapping(value = "/queryMember",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public String queryMember(@RequestParam(value = "num",required = false) Integer num,
                              @RequestParam(value = "size",required = false) Integer size){
        return hseCheckRecordService.queryMember(num,size);
    }

    //删除HSE审核人
    @RequestMapping(value = "/deleteCheckPerson",method = RequestMethod.DELETE,produces = "application/json; charset=utf-8")
    public String deleteCheckPerson(@ModelAttribute CheckPersonPojo checkPersonPojo){
        return hseCheckRecordService.deleteCheckPerson(checkPersonPojo.getCheckPersonID());
    }

    //一键审核问题
    // 2021.4.6 组长调用
    @RequestMapping(value = "/updateAllRecordStatusByByHeadman",method = RequestMethod.POST,produces = "application/json; charset=utf-8")
    public String updateAllRecordStatusByByHeadman(@RequestBody CheckRecordIDDto checkRecordIDDto, HttpServletRequest request){
        return hseCheckRecordService.updateAllRecordStatusByByHeadman(checkRecordIDDto,request);
    }

    //一键审核问题
    // 2021.4.6 管理员调用
    @RequestMapping(value = "/updateAllRecordStatusByAdmin",method = RequestMethod.POST,produces = "application/json; charset=utf-8")
    public String updateAllRecordStatusByAdmin(@RequestBody CheckRecordIDDto checkRecordIDDto, HttpServletRequest request){
        return hseCheckRecordService.updateAllRecordStatusByAdmin(checkRecordIDDto,request);
    }

    //根据checkPersonId修改HSE审核人员的RoleCode和RoleName
    @RequestMapping(value = "/updatePersonRole",method = RequestMethod.POST,produces = "application/json; charset=utf-8")
    public String updatePersonRole(@RequestBody CheckPerson checkPerson){
        return hseCheckRecordService.updatePersonRole(checkPerson);
    }

    //根据QHSEECheckPersonID集合批量删除
    @RequestMapping(value = "/deleteCheckPersons",method = RequestMethod.POST,produces = "application/json; charset=utf-8")
    public String deleteCheckPersons(@RequestBody List<String> checkPersonList){
        return hseCheckRecordService.deleteCheckPersons(checkPersonList);
    }
    @ApiOperation("查Name like“QHSEE”的所有数据")
    @RequestMapping(value = "/queryNameLikeQhsee",method = RequestMethod.GET,produces = "application/json; charset=utf-8")
    public R queryNameLikeQhsee(){
        return hseCheckRecordService.queryNameLikeQhsee();
    }

}
